﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _3D_FileExplorer
{
    class TreeCreator
    {
        private TreeDataProvider tdp;

        public TreeCreator(TreeDataProvider tdp) {
            this.tdp = tdp;
        }


        //Constructor for second and more loads
        public List<Node> Build(string root, int branchLevel)
        {
            List<Node> nodeList = new List<Node>();
            nodeList.Add(tdp.getNode(root));
            if (nodeList[0] is InnerNode)
            {
                BuildTree((InnerNode)nodeList[0], branchLevel-1);
            }
            return nodeList;
        }

        private void BuildTree(InnerNode root, int branchLevel)
        {
            root.Branch = tdp.getChildrenOfNode(root.Name);
            if (branchLevel > 0)
            {
                foreach (Node nd in root.Branch)
                {
                    if (nd is InnerNode)
                    {
                        BuildTree((InnerNode)nd, branchLevel - 1);
                    }
                }
            }
            
        }
    }
}


